<!--
 - Author : chenyliu.
 - Date   : 2016/9/9.
 - File   : wh-brand.vue.
 -->

<template>
  <tr>
    <td>{{brand.sysName}}</td>
    <td>
      <img class="logo-item" :src="brand.logo||defaultLogo">
    </td>
    <td>
      <div>
        <a href="javascript:;" title="查看公司" @click="detail(brand)">
          <i class="glyphicon glyphicon-link"></i>
          查看公司
        </a>&nbsp;
        <a href="javascript:;" title="编辑" @click="edit(brand)">
          <i class="glyphicon glyphicon-pencil"></i>
          编辑
        </a>&nbsp;
        <a href="javascript:;" title="删除" @click="del(brand)">
          <i class="glyphicon glyphicon-remove-circle"></i>
          删除
        </a>
      </div>
    </td>
  </tr>
</template>

<script>
  import Vue from 'vue';
  import WhBrand from '../../components/wh-brand';
  import apiSource from '../../wohome-api';
  import {token} from '../../vuex/getter';
  import {isEmptyObject} from '../../utils/tool';

  export default {
    props: {
      detail: {
        type: Function,
        default: function() {

        }
      },
      edit: {
        type: Function,
        default: function() {

        }
      },
      del: {
        type: Function,
        default: function() {

        }
      },
      brand: {
        type: Object,
        default: {"sysId": "", "sysName": "", "logo": "./static/brand_logo.png"}
      },
    },
    components: {WhBrand},
    data(){
      return {
        defaultLogo: "./static/brand_logo.png"
      }
    },
    vuex: {
      getters: {
        token
      }
    },
    ready(){
      this.getBrandLogo(this.brand.sysId);
    },
    methods: {
      getBrandLogo(sysId){
        if (!sysId) {
          return;
        }
        apiSource({
          type: 'outer',
          service: 'osysLogoGet',
          token: this.token,
          ct: {
            "sysId": sysId
          }
        }).then((res) => {
          var logo = res.logo;
          if (!isEmptyObject(res) && logo) {
            Vue.set(this.brand, "logo", logo)
          }
        });
      }
    }
  }
</script>

<style lang="less">
  @import "../../assets/less/pages.less";
</style>
